﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace ChurchDiary.Common
{
    public static class GuidComb
    {
        public static Guid Generate()
        {
            var buffer = Guid.NewGuid().ToByteArray();
            var time = new DateTime(0x76c, 1, 1);
            var now = DateTime.Now;
            var span = new TimeSpan(now.Ticks - time.Ticks);
            var timeofDay = now.TimeOfDay;

            var bytes = BitConverter.GetBytes(span.Days);
            var array = BitConverter.GetBytes((long)(timeofDay.TotalMilliseconds / 3.333333));
            Array.Reverse(bytes);
            Array.Reverse(array);
            Array.Copy(bytes, bytes.Length - 2, buffer, buffer.Length - 6, 2);
            Array.Copy(bytes, bytes.Length - 4, buffer, buffer.Length - 4, 4);
            return new Guid(buffer);
        }
        public static string GetUserid()
        {
            string Userid = "";
            if (HttpContext.Current.Session["Userid"].ToString() != null)
            {
                Userid = HttpContext.Current.Session["Userid"].ToString();
            }
            return Userid;
        }
    }
}
